package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark27Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class Mark27 extends BaseMark {

    LayoutWatermark27Binding binding;

    public Mark27(@NonNull Context context) {
        super(context);
    }

    public Mark27(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark27(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark27Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark27Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.binding7, binding.binding9, binding.bottom);
        }
    }

    @Override
    public void update() {
        setText(binding.binding1, "time27", "13:30", binding.binding1);
        setTime(binding.binding1, new SimpleDateFormat("HH:mm"));
        setTime(binding.binding3, new SimpleDateFormat("yyyy/MM/dd"));
        setWeek(binding.binding4);
        setText(binding.binding6, "didian27", binding.binding5);
        setText(binding.binding8, "jinwei27", binding.binding7);
        setText(binding.binding10, "beizhu27", binding.binding9);
        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("time27", "时间", true));
        list.add(new EditItem("didian27", "地点"));
        list.add(new EditItem("jingwei27", "经纬度"));
        list.add(new EditItem("beizhu27", "备注"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding1, new SimpleDateFormat("HH:mm"));
            setTime(binding.binding3, new SimpleDateFormat("yyyy/MM/dd"));
            setWeek(binding.binding4);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isTime) {
            if (item.show) {
                showView(binding.binding1, binding.binding2);
            } else {
                hideView(binding.binding1, binding.binding2);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
